import js from "@eslint/js";
import vue from "eslint-plugin-vue";

export default [
  // 忽略的文件
  {
    ignores: [
      "node_modules/**",
      "dist/**",
      "build/**",
      ".output/**",
      "public/**",
      "src/assets/icon/**",
      "*.min.js",
      ".env*",
      ".vscode/**",
      ".idea/**",
      "*.log",
    ],
  },

  // 基础 JavaScript 推荐规则
  js.configs.recommended,

  // Vue 推荐规则
  ...vue.configs["flat/essential"],

  // 自定义规则
  {
    files: ["**/*.{js,vue}"],
    languageOptions: {
      ecmaVersion: "latest",
      sourceType: "module",
      globals: {
        // Node.js 全局变量
        console: "readonly",
        process: "readonly",
        Buffer: "readonly",
        __dirname: "readonly",
        __filename: "readonly",
        exports: "writable",
        global: "readonly",
        module: "readonly",
        require: "readonly",

        // 浏览器全局变量
        window: "readonly",
        document: "readonly",
        localStorage: "readonly",
        sessionStorage: "readonly",
        setTimeout: "readonly",
        setInterval: "readonly",
        clearTimeout: "readonly",
        clearInterval: "readonly",
        FormData: "readonly",
        FileReader: "readonly",
        File: "readonly",
        Image: "readonly",
        crypto: "readonly",
        ElMessageBox: "readonly",

        // Vue 3 全局变量
        defineProps: "readonly",
        defineEmits: "readonly",
        defineExpose: "readonly",
        withDefaults: "readonly",
      },
    },
    rules: {
      // Vue 特定规则
      "vue/multi-word-component-names": "off",
      "vue/no-unused-vars": "off",
      "vue/no-v-html": "warn",

      // JavaScript 通用规则
      "no-console": "warn",
      "no-debugger": "error",
      "no-empty": "off",
      "no-unused-vars": "off",
      "no-async-promise-executor": "off",
      semi: ["error", "always"],
      quotes: ["error", "double"],
      indent: ["error", 2],
      "comma-dangle": "off",
      "object-curly-spacing": ["error", "always"],
      "array-bracket-spacing": ["error", "never"],
      "space-before-function-paren": "off",
      "keyword-spacing": "error",
      "space-infix-ops": "error",
      "eol-last": "error",
      "no-trailing-spaces": "error",
    },
  },
];
